package com.bc.db;

import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

import android.app.Application;
import android.content.Context;

public final class DBHelper extends SQLiteOpenHelper {

	private static final int DB_VERSION = 1;
	private static final String DB_NAME = "btc.db";


	public static final String ID_COL = "_id";

	//行情警报表
	public static final String WARN_TABLE = "warn";
	public static final String BUY_COL = "buy";
	public static final String OVER_COL = "over";
	public static final String MONEY_COL = "money";
	public static final String ENABLE_COL = "enable";
	public static final String TYPE_COL = "type";
	
	private DBHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	private static DBHelper instance;

	/** 在Application初始化 */
	public static void init(Application application) {
		instance = new DBHelper(application);
	}

	public static int ref = 0;

	public static DBHelper getInstance() {
		ref++;
		return instance;
	}

	@Override
	public void onCreate(SQLiteDatabase sqLiteDatabase) {
		sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS "+ WARN_TABLE + "(" +
			ID_COL +" INTEGER PRIMARY KEY autoincrement," +
	        BUY_COL +" INTEGER," +
	        OVER_COL +" INTEGER," +
	        MONEY_COL +" DOUBLE," +
	        TYPE_COL + " TEXT," +
	        ENABLE_COL +" INTEGER);"
		);
	}

	@Override
	public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
		sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + WARN_TABLE);
		onCreate(sqLiteDatabase);
	}

}
